import React, { useState, useEffect } from 'react'
import Header from '../../components/Header'
import { reqCoupon } from '../../http/api'
import ShowCoupon from './components/ShowCoupon/ShowCoupon'
import './coupon.less'
export default function Coupon() {
    // 1.初始数据
    const [list, setList] = useState([])
    // 5.初始n
    const [n, setN] = useState(0)
    // 2.一进页面就请求数据
    useEffect(() => {
        reqCoupon().then(res => {
            if (res.data.code === 200) {
                // 3.修改赋值
                setList(res.data.list)
            }
        })

    }, [])
    return (
        <div className="cou_bg">
            {/* 头部组件 */}
            <Header title="我的优惠券" back></Header>
            {/* 子组件 4.传给子组件 */}
            {
                list.length > 0 ? <ShowCoupon listShow={list[n].content} n={n} setN ={(e)=>setN(e)}></ShowCoupon> : null
            }

        </div>
    )
}
